import { FormType } from "../../views/system/data/role";
import { PageType } from '../../types/global'
import request from '../../utils/request.ts'
// 添加角色
export const apiAddRole = (data: FormType) => {
    return request({
        url: '/system/role/add',
        method: 'post',
        data: data
    });
}

// 编辑角色
export const apiUpdateRole = (data: FormType) => {
    return request({
        url: '/system/role/update',
        method: 'post',
        data: data
    });
}

// 分页角色
export const apiRolePage = (data: PageType) => {
    return request({
        url: '/system/role/page',
        method: 'get',
        data: data
    });
}

// 角色详情

export const apiRoleDetail = (roleId: number | string) => {
    return  request({
        url: '/system/role/detail?roleId=' + roleId,
        method: 'get'
    });
}

// 获取所有角色
export const apiRoleAll = async () => {
    let { data } = await request({
        url: '/system/role/list',
        method: 'get'
    });
    data = data.map((item: any) => ({ ...item, value: item.id })); // 组件需要的格式
    return data;
}

// 删除角色
export const apiRoleDelete =  (ids: any[]) => {
    return request({
        url: '/system/role/delete',
        method: 'post',
        data: { ids }
    });
}
